package com.dave.gd.core.services.caller;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.dave.gd.common.util.PropertiesUtil;
import com.dave.gd.common.util.StringUtils;
import com.dave.gd.core.services.utils.ServConstants;

/**
 * Created by linzq on 2014/11/3.
 */
public class CallUtils {
    
    private static final String                  DEFAULT_HOST = PropertiesUtil
                                                                  .getConfigValueCache(
                                                                      ServConstants.SERVICE_CONFIG_FILE,
                                                                      "defaulthost");
    
    private static final String                  BASE_SERVICE = PropertiesUtil
                                                                  .getConfigValueCache(
                                                                      ServConstants.SERVICE_CONFIG_FILE,
                                                                      "baseService");
    
    private static final String                  SEQ_SERVICE  = PropertiesUtil
                                                                  .getConfigValueCache(
                                                                      ServConstants.SERVICE_CONFIG_FILE,
                                                                      "seqService");
    
    private static ConcurrentMap<String, String> map          = new ConcurrentHashMap<String, String>();
    
    static {
        //初始化map
        map.putIfAbsent("seqService" + ServConstants.SERV_FACTORY_TAG + "nextId", SEQ_SERVICE);
        
    }
    
    public static String getUrl(String serviceName, String method) {
        String url = map.get(serviceName + ServConstants.SERV_FACTORY_TAG + method);
        if (StringUtils.isBlank(url)) {
            url = BASE_SERVICE;
        }
        return DEFAULT_HOST + url;
    }
}
